﻿using System.Data;
using l1cs.server.model.Instance;
using l1cs.server.utils;

namespace l1cs.server.model.trap
{
    public class L1DamageTrap : L1Trap
    {
        private readonly Dice _dice;
        private readonly int _base;
        private readonly int _diceCount;

        public L1DamageTrap( DataRow item )
            : base( item )
        {
            _dice = new Dice( SqlUtils.toInt( item["dice"] ) );
            _base = SqlUtils.toInt( item["base"] );
            _diceCount = SqlUtils.toInt( item["diceCount"] );
        }

        override public void onTrod( L1PcInstance trodFrom, L1Object trapObj )
        {
            sendEffect( trapObj );

            int dmg = _dice.roll( _diceCount ) + _base;

            trodFrom.receiveDamage( trodFrom, dmg, false );
        }
    }
}
